package com.hnichr.ump.ping.controller;

import com.hnichr.ump.common.ping.entity.SmsSendContent;
import com.hnichr.ump.common.ping.service.SmsSendContentService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sms/send/content/v1/")
@Tag(name = "SmsSendContentController", description = "短信发送内容接口")
public class SmsSendContentController {

    @Autowired
    private SmsSendContentService smsSendContentService;

    @GetMapping("list")
    @Operation(summary = "短信发送内容列表", description = "获取短信发送内容列表（无分页）", method = "GET")
    public Result<List<SmsSendContent>> list(@Parameter(description="查询参数") Criteria criteria){
        List<SmsSendContent> list = smsSendContentService.list(SmsSendContent.class,criteria);
        return Result.OK(list);
    }

    @GetMapping("page")
    @Operation(summary = "短信发送内容列表", description = "短信发送内容列表（分页）", method = "GET")
    public Result<Page<SmsSendContent>> page(@Parameter(description="查询参数")  Criteria criteria, @Parameter(description="每页条数")Integer pageSize, @Parameter(description="页号")Integer pageNo){
        Pageable page = PageRequest.of(pageNo-1, pageSize);
        Page<SmsSendContent> list = smsSendContentService.listPage(SmsSendContent.class,page, criteria);
        return Result.OK(list);
    }

    @GetMapping("list/{id}")
    @Operation(summary = "根据ID获取短信发送内容", description = "根据ID获取短信发送内容", method = "GET")
    public Result<SmsSendContent> getById(@Parameter(description="ID") @PathVariable(name = "id", required = true) String id) {
        SmsSendContent smsSendContent = smsSendContentService.getById(SmsSendContent.class, id);
        return Result.OK(smsSendContent);
    }

    @DeleteMapping("remove/{ids}")
    @Operation(summary = "根据id删除短信发送内容", description = "根据id删除短信发送内容", method = "DELETE")
    public Result<SmsSendContent> remove(@PathVariable(name = "ids", required = true) String ids) {
        try{
            smsSendContentService.remove(ids);
        }
        catch (Exception e){
            return Result.error(e.getMessage());
        }
        return Result.OK();
    }
}
